package com.gp.geits.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


import com.gp.geits.utils.PageUtils;
import com.gp.geits.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.gp.geits.entity.PositionEntity;
import com.gp.geits.service.PositionService;

import javax.servlet.http.HttpServletRequest;


/**
 * 
 *
 * @author lzf
 * @date 2022-03-09 15:36:11
 */
@RestController
@RequestMapping("/position")
public class PositionController {
    @Autowired
    private PositionService positionService;

    /**
     * 发布职位信息
     */
    @PostMapping("positionPublish")
    public R positionPublish(@RequestBody PositionEntity positionEntity,
                             HttpServletRequest request){
        positionService.positionPublish(positionEntity,request);
        return R.ok().message("发布成功");
    }

    /**
     * 查询当前用户发布的职位信息
     */
    @GetMapping("positionByUserId")
    public R positionByUserId(HttpServletRequest request){
        List<PositionEntity> positionEntityList = positionService.positionByUserId(request);
        return R.ok().data("positionEntityList",positionEntityList);
    }

    /**
     * 列表
     */
    @GetMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = positionService.queryPage(params);

        return R.ok().data("page", page);
    }


    /**
     * 信息
     */
    @GetMapping ("/info/{id}")
    public R info(@PathVariable("id") Integer id){
		PositionEntity position = positionService.getById(id);

        return R.ok().data("position", position);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody PositionEntity position){
		positionService.save(position);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody PositionEntity position){
		positionService.updateById(position);

        return R.ok().message("修改成功");
    }

    /**
     * 当前用户删除已发布职位信息
     */
    @PostMapping("/delete")
    public R delete(@RequestBody Integer[] ids){
		positionService.removeByIds(Arrays.asList(ids));

        return R.ok().message("删除成功");
    }

}
